package com.niiwoo.civet.trade.service.local.newRefund.notify.mq;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.niiwoo.asset.cardniu.enums.ProjectStatusEnum;
import com.niiwoo.asset.dto.mq.R360OrderStatusChangedDTO;
import com.niiwoo.asset.enums.r360.R360OrderProjectSubStatusEnum;
import com.niiwoo.asset.enums.r360.R360OrderStatusEnum;
import com.niiwoo.civet.trade.dao.entity.Project;
import com.niiwoo.civet.trade.enums.ProjectSubStatusEnum;
import com.niiwoo.civet.trade.service.local.newRefund.notify.dto.RefundNotifyDTO;
import com.niiwoo.civet.trade.service.local.newRefund.notify.enums.RefundNotifyEnum;

/**
 * 融360标的状态变更MQ通知
 * 
 * 触发条件：标的逾期、标的结清、标的逾期到正常还款
 *
 * @author: kevin.jia
 * @version 1.0.0
 */
@Component
public class R360ProjectStatusChangeNotify extends MQRefundNotify {
	
	@Override
	public Object bulidParam(RefundNotifyDTO refundNotifyDTO) {
		Project project = refundNotifyDTO.getProject();
		
		// 此方法只处理还款、结清的状态变更
		if (ProjectStatusEnum.REPAYING.getStatus() !=  project.getStatus() && ProjectStatusEnum.FINISH.getStatus() !=  project.getStatus()) {
			return null;
		}
		
        R360OrderStatusChangedDTO r360OrderStatusChangedDTO = new R360OrderStatusChangedDTO();
        r360OrderStatusChangedDTO.setProjectId(project.getProjectId());
        r360OrderStatusChangedDTO.setR360OrderProjectSubStatusEnum(R360OrderProjectSubStatusEnum.enumOf(project.getSubStatus()));
		if (ProjectStatusEnum.FINISH.getStatus() == project.getStatus()) {
			r360OrderStatusChangedDTO.setR360OrderStatusEnumCode(R360OrderStatusEnum.PAY_SUCCESS.getCode());
		} else if (ProjectSubStatusEnum.REPAYING_INIT.getSubStatus() == project.getSubStatus()) {
			r360OrderStatusChangedDTO.setR360OrderStatusEnumCode(R360OrderStatusEnum.REPAYING_NOMAL.getCode());
		} else if (ProjectSubStatusEnum.REPAYING_OVERDUE.getSubStatus() == project.getSubStatus()
				|| ProjectSubStatusEnum.REPAYING_BAD.getSubStatus() == project.getSubStatus()) {
			r360OrderStatusChangedDTO.setR360OrderStatusEnumCode(R360OrderStatusEnum.OVER_DATE.getCode());
		}        
        r360OrderStatusChangedDTO.setUpdateDate(new Date());
		return r360OrderStatusChangedDTO;
	}
	
	@Override
	public RefundNotifyEnum getType() {
		return RefundNotifyEnum.R360_PROJECT_STATUS_CHANGE;
	}
}